import pymysql

# 打开数据库连接
db = pymysql.connect("localhost", "root", "admin", "mysql")
# 通过游标建立数据库对象
cursor = db.cursor()

#插入
sql_insert = '''
insert into model (carname, carmodel, brand) values ("兰博基尼","跑车","兰博基尼") 
'''
#查询
sql_select = '''
select * from model
'''
#更新
sql_update = '''
update model set carname = '%s' where id = %s
'''%('奥迪A8', 1)

try:
    cursor.execute(sql_update)
    # data = cursor.fetchall()
    #
    # for d in data:
    #     print("车名 = %s , 车型 = %s" %(d[1], d[2]))

    db.commit()
except:
    print("error")
    db.rollback()
db.close()